package com.huawei.translate.model;

import com.huawei.translate.vo.application.ApplicationDto;

import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import java.util.Date;

@javax.persistence.Entity(name = "APPLICATION")
public class Application extends BaseEntity {
    private String appName;
    private Date onlineDate;
    private String accessCountPerSec;
    private String languages;
    private String description;
    private String productOwner;
    private String poEmail;
    private String interfacePerson;
    private String iPersonEmail;
    private int status;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "RENTER_ID")
    private Renter renter;

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public Date getOnlineDate() {
        return onlineDate;
    }

    public void setOnlineDate(Date onlineDate) {
        this.onlineDate = onlineDate;
    }

    public String getAccessCountPerSec() {
        return accessCountPerSec;
    }

    public void setAccessCountPerSec(String accessCountPerSec) {
        this.accessCountPerSec = accessCountPerSec;
    }

    public String getLanguages() {
        return languages;
    }

    public void setLanguages(String languages) {
        this.languages = languages;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getProductOwner() {
        return productOwner;
    }

    public void setProductOwner(String productOwner) {
        this.productOwner = productOwner;
    }

    public String getPoEmail() {
        return poEmail;
    }

    public void setPoEmail(String poEmail) {
        this.poEmail = poEmail;
    }

    public String getInterfacePerson() {
        return interfacePerson;
    }

    public void setInterfacePerson(String interfacePerson) {
        this.interfacePerson = interfacePerson;
    }

    public String getiPersonEmail() {
        return iPersonEmail;
    }

    public void setiPersonEmail(String iPersonEmail) {
        this.iPersonEmail = iPersonEmail;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Renter getRenter() {
        return renter;
    }

    public void setRenter(Renter renter) {
        this.renter = renter;
    }

    public ApplicationDto toDto() {
        ApplicationDto dto = new ApplicationDto();
        dto.setAppId(getId());
        dto.setAppName(appName);
        dto.setProductOwner(productOwner);
        dto.setLanguages(languages);
        dto.setInterfacePerson(interfacePerson);
        dto.setApplyDate(getCreatedAt());
        dto.setOnlineDate(onlineDate);
        dto.setStatus(status);
        dto.setAccessCountPerSec(accessCountPerSec);
        dto.setDescription(description);
        dto.setProductOwnerEmail(poEmail);
        dto.setInterfacePersonEmail(iPersonEmail);
        if (this.renter == null) {
            dto.setAppKey("");
            dto.setType("");
        } else {
            dto.setAppKey(renter.getAppKey());
            dto.setType(renter.getCategory());
            dto.setAppSecret(renter.getAppSecret());
        }
        return dto;
    }
}
